using System;
using System.Collections.Generic;
using System.Text;

namespace interfaces
{
	public static class Building
	{
		/// <summary>
		/// Building floor area input type
		/// </summary>
		public enum BEE_BuildingFloorArea_T
		{
			Total_BFAT,				// total floor area,						user-input
			Conditioned_BFAT,		// conditioned floor area,					user-input
			Envelope_BFAT,			// envelope (wall + window + roof) area,	calculated
			Roof_BFAT,				// roof area,								calculated
			Facade_BFAT,			// facade area (wall + window),				calculated
			Wall_BFAT,				// wall area,								calculated
			Window_BFAT,			// window area,								calculated
			Refrigeration_BFAT,		// refrigeration area (floor area),			user-input
			LightingControl_BFAT,	// lighting control area (office, conference room, stock, corridor, rest room etc non-public feature rooms), calculated
			GeneralLighting_BFAT,
			TaskLighting_BFAT,
			Elevator_BFAT,
			Escalator_BFAT,
			NUM_BFAT
		};

		public static List<string> BEE_strBuildingFloorArea = new List<string> (new string[]
		{ 
			"Floor",
			"Conditioned",
			"Envelope",
			"Roof",
			"Facade",
			"Wall",
			"Window",
			"Refrigeration",
			"LightingControl",
			"GeneralLighting",
			"TaskLighting",
			"Elevator",
			"Escalator"
		});

/*		public enum BEE_BuildingAreaRatio_T
		{
			Total_BART,				
			Conditioned_BART,		
			Envelope_BART,			
			Roof_BART,				
			Facade_BART,			
			Wall_BART,				
			WWR_BART,				// WWR
			Refrigeration_BART,		// area ratio of refrigeration system. (right now only 0 or 1)
			LightingControl_BART,	// lighting control area (used for lighting cost estimation)
			GeneralLighting_BART,
			TaskLighting_BART,
			Elevator_BART,
			Escalator_BART,
			NUM_BART
		};*/

		/// <summary>
		/// building default area constant,
		/// the default floor is used to scale user-input floor area.
		/// 1st dimension is accessed by interf.BEE_Building_T, 
		/// 2nd dimension is accessed by BEE_BuildingFloorArea_T
		/// </summary>
		public static double[][] BEE_Area = new double[][]
		{
			new double[] {36000, 30400, 15760, 4000, 11760, 9408, 2352, 1600, 4320, 0, 0, 0, 0 },	// ShoppingMall_BT
			new double[] {10000, 10000,  0,		0,		0,	0,		0,	0,		0, 0, 0, 0	},	// TODO, Office_BT
			new double[] {40000, 40000,  0,		0,		0,	0,		0,	0,		0, 0, 0, 0	},	// TODO, Hospital
			new double[] {40000, 40000,  0,		0,		0,	0,		0,	0,		0, 0, 0, 0	},	// TODO, Hotel
			new double[] {10000, 10000,  0,		0,		0,	0,		0,	0,		0, 0, 0, 0	},	// TODO, School
			new double[] {10000, 10000,  0,		0,		0,	0,		0,	0,		0, 0, 0, 0	}	// TODO, Other
		};

		/// <summary>
		/// building default area constant,
		/// the default floor is used to scale user-input floor area.
		/// 1st dimension is accessed by interf.BEE_Building_T, 
		/// 2nd dimension is accessed by BEE_BuildingAreaRatio_T
		/// </summary>
		public static double[][] BEE_AreaRatio = new double[][]
		{
			new double[] {1, 0, 0, 0, 0, 0, 0.2, 0.12, 0.16, 0.33, 0.67, 0.2, 0.8},	// ShoppingMall_BT
			new double[] {1, 0, 0, 0, 0, 0, 0.2, 0.8, 0.5, 0.33, 0.67, 0.2, 0.8},	// TODO, Office_BT
			new double[] {1, 0, 0, 0, 0, 0, 0.2, 0.12, 0.5, 0.33, 0.67, 0.2, 0.8},	// TODO, Hospital
			new double[] {1, 0, 0, 0, 0, 0, 0.2, 0.2, 0.5, 0.33, 0.67, 0.2, 0.8},	// TODO, Hotel
			new double[] {1, 0, 0, 0, 0, 0, 0.2, 0.2, 0.5, 0.33, 0.67, 0.2, 0.8},	// TODO, School
			new double[] {1, 0, 0, 0, 0, 0, 0.2, 0.2, 0.5, 0.33, 0.67, 0.2, 0.8}	// TODO, Other
		};

		/// <summary>
		/// Building economic input type
		/// </summary>
		public enum BEE_BuildingEconomic_T
		{
			DiscountRate_BET,
			EvaluationPeriod_BET,
			NUM_BET
		};

		/// <summary>
		/// calculate building areas based on input floor area and wwr value.
		/// </summary>
		/// <param name="type"></param>
		/// <param name="area"></param>
		/// <param name="ratio"></param>
		/// <returns></returns>
		public static double[] extrpolateAreas(interf.BEE_Building_T type, double[] area, double[] ratio)
		{
			double[] new_area = area;
			double floor_area_ratio = area[(int)BEE_BuildingFloorArea_T.Total_BFAT] / BEE_Area[(int)type][(int)BEE_BuildingFloorArea_T.Total_BFAT];
			double envelope_area_ratio = Math.Sqrt(floor_area_ratio);

			ratio[(int)BEE_BuildingFloorArea_T.LightingControl_BFAT] = BEE_AreaRatio[(int)type][(int)BEE_BuildingFloorArea_T.LightingControl_BFAT];
			ratio[(int)BEE_BuildingFloorArea_T.GeneralLighting_BFAT] = BEE_AreaRatio[(int)type][(int)BEE_BuildingFloorArea_T.GeneralLighting_BFAT];
			ratio[(int)BEE_BuildingFloorArea_T.TaskLighting_BFAT] = BEE_AreaRatio[(int)type][(int)BEE_BuildingFloorArea_T.TaskLighting_BFAT];
			ratio[(int)BEE_BuildingFloorArea_T.Elevator_BFAT] = BEE_AreaRatio[(int)type][(int)BEE_BuildingFloorArea_T.Elevator_BFAT];
			ratio[(int)BEE_BuildingFloorArea_T.Escalator_BFAT] = BEE_AreaRatio[(int)type][(int)BEE_BuildingFloorArea_T.Escalator_BFAT];

			// roof area, direct floor area relationship
			new_area[(int)BEE_BuildingFloorArea_T.Roof_BFAT] = BEE_Area[(int)type][(int)BEE_BuildingFloorArea_T.Roof_BFAT] * floor_area_ratio;
			// facade area, sqrt floor area relationship
			new_area[(int)BEE_BuildingFloorArea_T.Facade_BFAT] = BEE_Area[(int)type][(int)BEE_BuildingFloorArea_T.Facade_BFAT] * envelope_area_ratio;
			// wall area, sqrt floor area relationship
			new_area[(int)BEE_BuildingFloorArea_T.Wall_BFAT] = new_area[(int)BEE_BuildingFloorArea_T.Facade_BFAT] * (1 - ratio[(int)BEE_BuildingFloorArea_T.Window_BFAT]);
			// window area, sqrt floor area relationship
			new_area[(int)BEE_BuildingFloorArea_T.Window_BFAT] = new_area[(int)BEE_BuildingFloorArea_T.Facade_BFAT] * ratio[(int)BEE_BuildingFloorArea_T.Window_BFAT];
			// refrigeration area, sacle based on floor area
			new_area[(int)BEE_BuildingFloorArea_T.Refrigeration_BFAT] = BEE_Area[(int)type][(int)BEE_BuildingFloorArea_T.Refrigeration_BFAT] * floor_area_ratio;

			// envelope area, sum up facade and roof area.
			new_area[(int)BEE_BuildingFloorArea_T.Envelope_BFAT] = new_area[(int)BEE_BuildingFloorArea_T.Facade_BFAT] + new_area[(int)BEE_BuildingFloorArea_T.Roof_BFAT];

			new_area[(int)BEE_BuildingFloorArea_T.LightingControl_BFAT] = new_area[(int)BEE_BuildingFloorArea_T.Total_BFAT] * ratio[(int)BEE_BuildingFloorArea_T.LightingControl_BFAT];

			return new_area;
		}

	}
}
